package com.study.opensource.spring.enable.selector;

import com.study.opensource.spring.enable.annotation.EnableServer;
import com.study.opensource.spring.enable.config.FtpServer;
import com.study.opensource.spring.enable.config.HttpServer;
import com.study.opensource.spring.enable.config.Server;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author 许棒棒
 * @className com.study.study.opensource.spring.enable.selector.ServerImportSelector
 * @description TODO 类描述
 * @date 2021/04/17 22:17:23
 */
public class ServerImportSelector implements ImportSelector {


    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {

        Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(EnableServer.class.getName());
        Server.Type type = (Server.Type) annotationAttributes.get("type");
        if (Server.Type.HTTP == type) {
            return new String[]{HttpServer.class.getName()};
        } else if (Server.Type.FTP == type) {
            return new String[]{FtpServer.class.getName()};
        }
        return new String[0];
    }
}
